<?php
namespace app\index\controller;

use app\index\model\Comment as CommentModal;
use app\index\validate\CommentValidate;
use app\index\validate\PageValidate;
use think\Controller;

class Index extends Controller
{
    // 主页
    public function index(){
        return view('index');
    }
    // 留言页
    public function message(){
        return view('message');
    }
    // 插入留言    // success 返回1   fail  返回0
    public function insertComment($name,$comment){
        (new CommentValidate())->goCheck();
        if($name == 1) $name = '';
        return CommentModal::insertComment($name,$comment);
    }
    // 留言展示
    public function getComment($page){
        (new PageValidate())->goCheck();
//        $count = CommentModal::getCountComment();
        $pageSize = 8;
        $start = ($page-1)*$pageSize;
        $list = CommentModal::getComment($start,$pageSize);
        return json($list);
    }

}
